/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.common.utils;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author fanshengchao
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-6-25 下午04:51:14          fanshengchao        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class CrontabUtil {

    public static String CronParser(String expr) {
        String descript = "";
        String[] arrays = expr.split(" ");
        if ("?".equals(arrays[5])) {
            if ("*".equals(arrays[3])) {
                // 说明是日暂停
                descript += "每天";
            } else {
                // 月暂停
                descript = "每月" + arrays[3] + "号";
            }
        } else {
            // 说明是按星期
            descript = "每周星期";
            if (arrays[5].equals("2"))
                descript += "一";
            else if (arrays[5].equals("3"))
                descript += "二";
            else if (arrays[5].equals("4"))
                descript += "三";
            else if (arrays[5].equals("5"))
                descript += "四";
            else if (arrays[5].equals("6"))
                descript += "五";
            else if (arrays[5].equals("7"))
                descript += "六";
            else if (arrays[5].equals("1"))
                descript += "日";
        }
        descript += "的" + arrays[2] + "时" + arrays[1] + "分";
        return descript;
    }

    public static String parseSimple(int duration) {
        String descript = "";
        int durHour = duration / 3600;

        int durDay = 0;
        int durMin = 0;
        int durSS = 0;
        if (durHour > 23) {
            durDay = durHour / 24;
            descript += durDay + "天";
            durHour = durHour % 24;
            durMin = (duration - durDay * 24 * 3600 - durHour * 3600) / 60;
            durSS = duration - durDay * 24 * 3600 - durHour * 3600 - durMin * 60;
        } else {
            durMin = (duration - durHour * 3600) / 60;
            durSS = duration - durHour * 3600 - durMin * 60;
        }
        if (durHour > 0) {
            descript += durHour + "小时";
        }
        if (durMin > 0) {
            descript += durMin + "分钟";
        }
        if (durSS > 0) {
            descript += durSS + "秒";
        }
        return descript;
    }

}
